package com.xiaohao.communication.controller;

import com.xiaohao.communication.bean.ConcernAndUnsubscribe;
import com.xiaohao.communication.dao.UserConcernAndUnsubscribeDao;
import com.xiaohao.communication.service.UserConcernAndUnsubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/*
* 用户关注与退订
* */
@Controller
public class UserConcernAndUnsubscribeController {


    @Autowired
    UserConcernAndUnsubscribeService userConcernAndUnsubscribeService;

    /*
    * 关注用户              success
    * 只需要传入关注者和被关注者即可。
    * 在dao层将   withUsernameState（被关注用户名状态码）  置为1
    * */
    @GetMapping("/follow-user")
    @ResponseBody
    public void concernUser(ConcernAndUnsubscribe concernAndUnsubscribe) {

        userConcernAndUnsubscribeService.concernUser(concernAndUnsubscribe);
    }


    /*
     * 取消关注用户           success
     * withusername:被关注用户名
     * Username:关注用户名
     * 传入之后，修改  被关注用户名状态码  ，置为0
     * */
    @GetMapping("/remove-user")
    @ResponseBody
    public void cancelConcernUser(String withUsername, String username) {

        userConcernAndUnsubscribeService.cancelConcernUser(withUsername, username);

    }


    /*
     * 获取关注用户           success
     * username：关注用户名
     * 传入 关注用户名，
     * */
    @GetMapping("/query-follow-user")
    @ResponseBody
    public List<ConcernAndUnsubscribe> getConcernUser(String username) {
        List<ConcernAndUnsubscribe> concernUser = userConcernAndUnsubscribeService.getConcernUser(username);
        return concernUser;

    }



    /*******************************/

    //关注话题              sucess
    /*
    * 传入关注者姓名  username
    *     话题id      topic_id
    *     被关注话题状态码 在dao层设置  topicState（不用传）
    *
    * */
    @GetMapping("/follow-topic")
    @ResponseBody
    public void concernTopic(ConcernAndUnsubscribe concernAndUnsubscribe) {
        userConcernAndUnsubscribeService.concernTopic(concernAndUnsubscribe);
    }


    /*
    * 取消关注话题            success
    *
    * topic_id  ： 关注话题id
    * username  ： 关注用户
    * 传入参数 设置被关注话题状态码 为 0；
    * */
    @GetMapping("/remove-topic")
    @ResponseBody
    public void cancelConcernTopic(int topic_id, String username) {

        userConcernAndUnsubscribeService.cancelConcernTopic(topic_id, username);

    }



    //获取关注话题            success
    @GetMapping("/query-follow-topic")
    @ResponseBody
    public List<ConcernAndUnsubscribe> getConcernTopic(String username) {

        List<ConcernAndUnsubscribe> concernTopic = userConcernAndUnsubscribeService.getConcernTopic(username);
        return concernTopic;

    }



}
